<script src="../jquery.js"></script>
<script type="text/javascript" charset="utf-8">
function init() {
	for(var i = 0; i < 3; i++){
		var newDiv = $("<div>Box #" + i + "</div>");
		newDiv.appendTo("#container");
		newDiv.click(
			(function(i){
				return function (){ alert(i) };
			})(i)
		)
	}
}
	$(document).ready(init);
</script>
<body>
	<div id="container"></div>